package com.ask.service.impl;

import com.ask.dao.MongoAskRepository;
import com.ask.dto.QuestionParam;
import com.ask.model.Question;

import com.ask.model.User;
import com.ask.service.QuestionService;
import org.springframework.stereotype.Service;

import org.springframework.beans.factory.annotation.Autowired;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Service
public class QuestionServiceImp implements QuestionService {
    private final Logger logger = LoggerFactory.getLogger(QuestionServiceImp.class);


    @Autowired
    private MongoAskRepository mongoAskRepository;

    /**
     * 提问
     */
    @Override
    public Question ask(QuestionParam questionParam){
        Question question = new Question();
        question.setTitle(questionParam.getTitle());
        question.setContent(questionParam.getContent());
        mongoAskRepository.save(question);//本来有save接口
        question.setQuestionId(question.getId());
        return question;
    }

    @Override
    public Question update(QuestionParam questionParam){
        Question question = mongoAskRepository.findByQuestionId(questionParam.getQuestionId());
        question.setTitle(questionParam.getTitle());
        question.setContent(questionParam.getContent());
        mongoAskRepository.save(question);//本来有save接口
        return question;
    }
}
